package com.jswlw.service.biz.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jswlw.dao.biz.ApiFailMapper;
import com.jswlw.dao.biz.DevInfoMapper;
import com.jswlw.entity.biz.ApiFail;
import com.jswlw.entity.biz.DevInfo;
import com.jswlw.service.biz.ApiFailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @author 吴维斌 E-mail:wuweibin0817@163.com
 * @version 创建时间：${date} ${time}
 */
@Slf4j
@Service
public class ApiFailServiceImpl implements ApiFailService {
    @Autowired
    ApiFailMapper mapper;
    @Autowired
    DevInfoMapper devInfoMapper;

    @Override
    public void add(ApiFail apiFail) {
        DevInfo devInfo = devInfoMapper.find4Imei(apiFail.getIcCid());
        if (Objects.nonNull(devInfo)) {
            apiFail.setDevId(devInfo.getId());
        }
        mapper.insert(apiFail);
    }

    @Override
    public void update(ApiFail apiFail) {
        mapper.updateByPrimaryKeySelective(apiFail);
    }

    @Override
    public void delete(Integer id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public ApiFail find4d(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ApiFail> queryList(ApiFail record) {
        return mapper.queryList(record);
    }

    @Override
    public List<ApiFail> query4List(ApiFail apiFail) {
        return mapper.query4List(apiFail);
    }

    @Override
    public Page<ApiFail> queryPage(ApiFail apiFail) {
        PageHelper.startPage(apiFail.getOffset(), apiFail.getLimit());
        return (Page<ApiFail>) mapper.query4List(apiFail);
    }
}
